package gsw.demo.mvp.mvp.presenter;

import java.lang.ref.WeakReference;
import java.util.List;

import gsw.demo.mvp.mvp.bean.Girl;
import gsw.demo.mvp.mvp.model.GirlModel;
import gsw.demo.mvp.mvp.model.GirlModelImp;
import gsw.demo.mvp.mvp.view.IGirlView;

/**
 * 表示层：连接M层与V层，处理所有的业务逻辑
 */
public class GirlPresenter<T extends IGirlView> {
    //1.view层的引用。使用弱引用：当内存不足时，可以被回收
    WeakReference<T> mView;
    //2.model层的引用
    GirlModel girlModel = new GirlModelImp();

    public GirlPresenter(T view) {
        this.mView = new WeakReference<T>(view);
    }

    //3.执行UI逻辑操作
    public void fetch() {
        if (mView.get() != null && girlModel != null) {
            girlModel.loadGirl(new GirlModel.GirlOnLoadListener() {
                @Override
                public void onComplete(List<Girl> list) {
                    mView.get().showGirls(list);
                }
            });
        }
    }
}








